import java.sql.*;
import org.postgresql.Driver;
import java.util.concurrent.TimeUnit;

public class test_jdbc_record_nettime_case0013 {
    public static void main(String[] args) throws Exception {
        System.out.println(Driver.getGSVersion());
        String url = "jdbc:postgresql://" + args[0] + "/" + args[1];
        String username = args[2];
        String password = args[3];
        String sql1,sql2,sql3,sql4;

        System.out.println("-----新建连接-----");
        Connection conn = GetConnection(username, password, url);

        System.out.println("-----建表/插入数据/更新数据/清理表-----");
        try {
            sql1 = "create table t_jdbc_record_nettime_case0013(id int);";
            sql2 = "insert into t_jdbc_record_nettime_case0013 values (2),(30);";
            sql3 = "update t_jdbc_record_nettime_case0013 set id = 6 where id > 5;";
            sql4 = "drop table t_jdbc_record_nettime_case0013;";
            System.out.println(sql1 + sql2 + sql3 + sql4);
            PreparedStatement rn_create = conn.prepareStatement(sql1 + sql2 + sql3 + sql4);
            for (int i = 0; i < 10; i++) {
                rn_create.execute();
            }

            System.out.println("--------sleep 10s--------");
            TimeUnit.SECONDS.sleep(10);
            rn_create.close();

            System.out.println("--------sleep 10s--------");
            TimeUnit.SECONDS.sleep(10);
            conn.close();
        } catch (SQLException e) {
            System.out.println("ERROR:" + e.getMessage());
            e.printStackTrace();
        }
    }

    public static Connection GetConnection(String username, String passwd, String sourceURL) {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(sourceURL, username, passwd);
            System.out.println(sourceURL);
            System.out.println("Connection succeed");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return conn;
    }
}